// 思路：类似call，但返回的是函数
Function.prototype.defBind = function(target){
    if(typeof this !== 'function'){
        throw new TypeError('被绑定的对象需要是函数')
    }
    let _this = this
    let arg = [...arguments].slice(1)
    return function Fn(){
        //处理new的情况
        if(this instanceof Fn){
            return new _this(...arg,...arguments)
        }else{
            return _this.apply(target,arg.concat(...arguments))
        }
    }
}


function foo(x){
    console.log(x,this.y)
}
const obj={
    y:'y'
}
foo.defBind(obj,'x')() // x y
foo.defBind()() // undefined undefined
